def get_cookie(cookie_string):
    """
    将chrome的Cookie-Editor插件导出的HeaderString格式的文本，转换成键值对形式的Cookie

    :param cookie_string:chrome的Cookie-Editor插件导出的HeaderString格式的文本
    :return:键值对形式的Cookie
    """
    cookie_dict = {}
    for kv in cookie_string.split(";"):
        k = kv.split('=')[0]
        v = kv.split('=')[1]
        cookie_dict[k] = v
    return cookie_dict


def get_info_xpath_then_patten(source, xpath=None, patten=None):
    try:
        if xpath is not None:
            info = source.xpath(xpath).extract_first()
            if patten is not None:
                return patten.search(info).group(0)
            else:
                return info
        else:
            if patten is not None:
                return patten.search(source).group(0)
            else:
                return source
    except:
        return 'no match'



